package com.headStorm.mavlinkDemo;


import io.dronefleet.mavlink.protocol.MavlinkPacket;

public class MavlinkMessage<T> {
    private final MavlinkPacket packet;
    private final T payload;

    public MavlinkMessage(MavlinkPacket packet, T payload) {
        this.packet = packet;
        this.payload = payload;
    }

    public int getSequence() {
        return this.packet.getSequence();
    }

    public int getOriginSystemId() {
        return this.packet.getSystemId();
    }

    public int getOriginComponentId() {
        return this.packet.getComponentId();
    }

    public T getPayload() {
        return this.payload;
    }

    public byte[] getRawBytes() {
        return (byte[]) this.packet.getRawBytes().clone();
    }

    public boolean equals(Object o) {
        if (this == o) {
            return true;
        } else if (o != null && this.getClass() == o.getClass()) {
            MavlinkMessage<?> that = (MavlinkMessage) o;
            if (this.packet != null) {
                if (this.packet.equals(that.packet)) {
                    return this.payload != null ? this.payload.equals(that.payload) : that.payload == null;
                }
            } else if (that.packet == null) {
                return this.payload != null ? this.payload.equals(that.payload) : that.payload == null;
            }

            return false;
        } else {
            return false;
        }
    }

    public int hashCode() {
        int result = this.packet != null ? this.packet.hashCode() : 0;
        result = 31 * result + (this.payload != null ? this.payload.hashCode() : 0);
        return result;
    }

    public String toString() {
        return "MavlinkMessage{packet=" + this.packet + ", payload=" + this.payload + '}';
    }
}
